Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

432
Views
Randomly get Error SQLSTATE[HY000] [14] unable to open database file - PHP PDO

This error appears randomly. I'm able to write and read the database file, but sometimes doesn't work, even with the same request.

I tried to test just one connection (to avoid multiple, thinking that could be the problem), and also randomly fails.

I checked the permissions of the file(windows), and all in order (if not I wouldn't be able to write the file)

This is the code to connect to database:

class Con{

    private $pdo;

    public function conex($db){

        try{

            // $pdo = $this->pdo;

            if ($this->pdo == null){

                sleep(0.1);
                $this->pdo = new PDO("sqlite:../../content/engine/" . $db,"","",array(
                    PDO::ATTR_PERSISTENT => true
                ));

                $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);      

            } 

            return $this->pdo;


        }catch(PDOException $e){

            die( $e->getMessage());

        } finally{

            $this->pdo = null;

        }
    }
}

class Q_General extends Con{

    protected $db;

    public function __construct($db){

        if ($this->db == null){

            $this->db = $this->conex($db);
        }
        
    } 

    public function get_query($sql){

        $query = $this->db->prepare($sql);
        $query->execute();

        $res = $query->fetchAll();
        $query->closeCursor();

        return $res;

    }
}

I do the request with ajax, so I can control the number and order of request and setup a queue for every request with the purpose of avoid write or read at the same time.

Any clue what can I be doing wrong?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!